﻿using System;

namespace ECommerce.Administration.Controls
{
	public partial class EditProduct : AdminBaseUsercontrol
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!IsPostBack)
			{
				if (CommonHelper.QueryStringInt("productid") > 0)
				{
					LabelEditProductTitle.Text = GetLocalResourceString("Admin.EditProduct.Edit.Title");
				}
				else
				{
					LabelEditProductTitle.Text = GetLocalResourceString("Admin.EditProduct.Add.Title");
				}

				ButtonSave.Text = GetLocalResourceString("Admin.SaveButtonText");

				pnlBasicInfo.HeaderText = GetLocalResourceString("Admin.EditProduct.BasicInfoTabHeaderText");
				pnlCategoryMappings.HeaderText = GetLocalResourceString("Admin.EditProduct.CategoryMappingHeaderText");
				pnlTagMappings.HeaderText = GetLocalResourceString("Admin.EditProduct.TagMappingHeaderText");
				pnlRelatedProduct.HeaderText = GetLocalResourceString("Admin.EditProduct.RelatedProductHeaderText");
				pnlPictures.HeaderText = GetLocalResourceString("Admin.EditProduct.ProductPicturesHeaderText");
				pnlAdditionalProperties.HeaderText = GetLocalResourceString("Admin.EditProduct.AdditionalPropertiesHeaderText");
			}
		}

		protected void ButtonSave_Click(object sender, EventArgs e)
		{
			int theProductID = ProductBasicInfoControl.SaveTheProductBasicInfo();

			if(theProductID > 0)
			{
				this.ProductCateogryListControl.ProductID = theProductID;
				this.ProductTagListControl.ProductID = theProductID;
				this.ProductListControl.ProductID = theProductID;
				this.ProductPicturesControl.ProductID = theProductID;
				this.ProductAdditionalPropertyControl.ProductID = theProductID;
				ProductCateogryListControl.SaveSelectedProductCategory();
				ProductTagListControl.SaveTheProduct_Tag_Mapping();
			}
		}
	}
}